package test;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import model.Booking;
import model.Rates;
import model.Room;
import model.RoomHasBooking;
import model.RoomType;
import model.User;

import dao.impl.BookingDaoImpl;
import dao.impl.RatesDaoImpl;
import dao.impl.RoomDaoImpl;
import dao.impl.RoomHasBookingDaoImpl;
import dao.impl.RoomTypeDaoImpl;
import dao.impl.UserDaoImpl;
import dao.intf.BookingDao;
import dao.intf.RatesDao;
import dao.intf.RoomDao;
import dao.intf.RoomHasBookingDao;
import dao.intf.RoomTypeDao;
import dao.intf.UserDao;

import util.DBController;

public class Sample {
	
	private static UserDao userDao = new UserDaoImpl();
	private static BookingDao bookingDao = new BookingDaoImpl();
	private static RatesDao ratesDao = new RatesDaoImpl();
	private static RoomDao roomDao = new RoomDaoImpl();
	private static RoomHasBookingDao roomHasBookingDao = new RoomHasBookingDaoImpl();
	private static RoomTypeDao roomTypeDao = new RoomTypeDaoImpl();

	public static void main(String[] args) {
		/***	Room Availability		***/
		//	START DATE
		String start = "2013-04-08";
		System.out.println("Chosen Start Date: " + start);
		
		//	END DATE
		String end = "2013-04-10";
		System.out.println("Chosen End Date: " + end);
		
		List<Room> availableList = roomDao.getAvailableRooms(start, end, "1PRE");
		
		System.out.println("\nRoom availability test...");
		for(int i=0; i<availableList.size(); i++) {
			Room room;
			room = availableList.get(i);
			System.out.println("Results found, Room ID: " + room.getRoomId() + ", Room Type: " + room.getTypeId() + ", Status: " + room.getStatus());
		}
		
		/***	User		***/
		List<User> userList = userDao.getUserList();
		
		System.out.println("\nUser test...");
		for(int i=0; i<userList.size(); i++) {
			User user;
			user = userList.get(i);
			System.out.println("Results found, ID: " + user.getId() + ", Name: " + user.getFirstName());
		}
		
		User user = userDao.getUserById("1");
		System.out.println("\ngetUserById found, ID: " + user.getId() + ", Name: " + user.getFirstName() + " " + user.getLastName());
		
		/***	Booking		***/
		List<Booking> bookingList = bookingDao.getBookingList();
		
		System.out.println("\nBooking test...");
		for(int i=0; i<bookingList.size(); i++) {
			Booking booking;
			booking = bookingList.get(i);
			System.out.println("Results found, Booking ID: " + booking.getId() + ", Start Date: " + booking.getStart() + ", End Date: " + booking.getEnd());
		}
		
		Booking booking = bookingDao.getBookingById("1PRE-20130407-024020");
		System.out.println("\ngetBookingById found, Booking ID: " + booking.getId() + ", Start Date: " + booking.getStart() + ", End Date: " + booking.getEnd());
		
		/***	Rates		***/
		List<Rates> ratesList = ratesDao.getRatesList();
		
		System.out.println("\nRates test...");
		for(int i=0; i<ratesList.size(); i++) {
			Rates rates;
			rates = ratesList.get(i);
			System.out.println("Results found, Rates ID: " + rates.getId() + ", Description: " + rates.getDescription() + ", Duration: " + rates.getDuration());
		}
		
		Rates rates = ratesDao.getRatesById("STUD-R-1");
		System.out.println("\ngetRatesById found, Rates ID: " + rates.getId() + ", Description: " + rates.getDescription() + ", Duration: " + rates.getDuration());
		
		/***	Room		***/
		List<Room> roomList = roomDao.getRoomList();
		
		System.out.println("\nRoom test...");
		for(int i=0; i<roomList.size(); i++) {
			Room room;
			room = roomList.get(i);
			System.out.println("Results found, Room ID: " + room.getRoomId() + ", Room Type: " + room.getTypeId() + ", Status: " + room.getStatus());
		}
		
		Room room = roomDao.getRoomById("1012");
		System.out.println("\ngetRoomById found, Room ID: " + room.getRoomId() + ", Room Type: " + room.getTypeId() + ", Status: " + room.getStatus());
		
		/***	RoomHasBooking		***/
		List<RoomHasBooking> roomHasBookingList = roomHasBookingDao.getBookingListByRoomId("1012");
		
		System.out.println("\nRoomHasBooking test...");
		for(int i=0; i<roomHasBookingList.size(); i++) {
			RoomHasBooking roomHasBooking;
			roomHasBooking = roomHasBookingList.get(i);
			System.out.println("Results found, Room ID: " + roomHasBooking.getRoomId() + ", Booking ID: " + roomHasBooking.getBookingId());
		}
		
		/***	RoomType		***/
		List<RoomType> roomTypeList = roomTypeDao.getRoomTypeList();
		
		System.out.println("\nRoomType test...");
		for(int i=0; i<roomTypeList.size(); i++) {
			RoomType roomType;
			roomType = roomTypeList.get(i);
			System.out.println("Results found, Room Type ID: " + roomType.getId() + ", Name: " + roomType.getName() + ", Description: " + roomType.getDescription() + ", No. of rooms: " + roomType.getNoOfRooms() + ", Rate: " + roomType.getRate());
		}
		
		RoomType roomType = roomTypeDao.getRoomTypeById("STUD");
		System.out.println("\ngetRoomTypeById found, Room Type ID: " + roomType.getId() + ", Name: " + roomType.getName() + ", Description: " + roomType.getDescription() + ", No. of rooms: " + roomType.getNoOfRooms() + ", Rate: " + roomType.getRate());
		
		/*try {
			// TEST CONNECTION
			ResultSet rs = DBController.retrieve("User", null, null);
			System.out.println("Select all records...");
			if( rs != null ) {
				while( rs.next() ) {
					int id = rs.getInt("Id");
					String name = rs.getString("Name");
					System.out.println("Results found, ID: " + id + ", Name: " + name);
				}
			}
			
			rs = DBController.retrieve("User", "Name", null);
			System.out.println("\nSelect specific column(s)...");
			if( rs != null ) {
				while( rs.next() ) {
					String name = rs.getString("Name");
					System.out.println("Results found, Name: " + name);
				}
			}
			
			rs = DBController.retrieve("User", null, "Name != 'ABC' && Id != 3");
			System.out.println("\nSelect records based on condition...");
			if( rs != null ) {
				while( rs.next() ) {
					int id = rs.getInt("Id");
					String name = rs.getString("Name");
					System.out.println("Results found, ID: " + id + ", Name: " + name);
				}
			}
			
			DBController.disconnect();
		} catch (SQLException e) {
			System.out.println("Error at method main() of Sample.");
			e.printStackTrace();
		}*/
	}
}
